import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  { path: '/', redirect: '/login' },
  {
    path: '/404',
    component: resolve => require(['@/views/error-page/404'], resolve),
    meta: {
      title: '很抱歉，您访问的页面不存在~',
      icon: ''
    },
    hidden: true
  },
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: resolve => require(['@/views/redirect/index'], resolve)
      }
    ]
  },
  {
    path: '/login',
    component: resolve => require(['@/views/login/index'], resolve),
    hidden: true
  },
  {
    path: '/dashboard',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: resolve => require(['@/views/dashboard/index'], resolve),
        name: 'dashboard',
        meta: { title: '首页', icon: 'iconfont icon-main', affix: true }
      }
    ]
  },
  {
    path: '/device',
    component: Layout,
    meta: {
      title: '终端管理',
      icon: 'terminal'
    },
    children: [{
        path: 'device-list',
        component: resolve => require(['@/views/device/device-info/index'], resolve),
        name: 'device-list',
        meta: { title: '终端管理', icon: 'ending' }
      },{
        path: 'device-monitor',
        component: resolve => require(['@/views/device/device-monitor/index'], resolve),
        name: 'device-monitor',
        meta: { title: '终端监控', icon: 'monitor' }
      },
      {
        path: 'device-logs',
        component: resolve => require(['@/views/device/device-log/index'], resolve),
        name: 'device-logs',
        meta: { title: '终端日志', icon: 'log' },
      }
    ]
  },
  {
    path: '/screen',
    component: Layout,
    meta: {
      title: '屏幕管理',
      icon: 'setup'
    },
    children: [{
        path: 'set-screen',
        component: resolve => require(['@/views/screen/set-screen'], resolve),
        name: 'set-screen',
        meta: { title: '屏幕设置', icon: 'screen' }
      }
    ]
  },
  {
    path: '/news',
    component: Layout,
    meta: {
      title: '新闻与节目',
      icon: 'system'
    },
    children: [{
        path: 'template-media-center',
        component: resolve => require(['@/views/news-program/media-center/index'], resolve),
        name: 'template-media-center',
        meta: { title: '新闻媒体', icon: 'meiti' }
      },{
        path: 'rong-media',
        component: resolve => require(['@/views/news-program/rong-media/index'], resolve),
        name: 'news-rongmedia',
        meta: { title: '融媒体', icon: 'roles' }
      },{
        path: 'template',
        component: resolve => require(['@/views/news-program/template/index'], resolve),
        name: 'news-template',
        meta: { title: '模板管理', icon: 'roles' }
      },{
        path: 'assembly',
        component: resolve => require(['@/views/news-program/assembly/index'], resolve),
        name: 'news-assembly',
        meta: { title: '自定义组件', icon: 'roles' }
      },{
        path: 'home',
        component: resolve => require(['@/views/news-program/news/home/index'], resolve),
        name: 'news-home',
        meta: { title: '首页制作', icon: 'roles' }
      },{
        path: 'page',
        component: resolve => require(['@/views/news-program/news/page/index'], resolve),
        name: 'news-page',
        meta: { title: '分页制作', icon: 'roles' }
      }
    ]
  },
  {
    path: '/media',
    component: Layout,
    meta: {
      title: '媒体节目',
      icon: 'media'
    },
    children: [{
      path: 'media-center',
      component: resolve => require(['@/views/media/media-center/index'], resolve),
      name: 'media-center',
      meta: { title: '节目媒体', icon: 'meiti' }
    }, {
      path: 'media-audit',
      component: resolve => require(['@/views/media/media-audit/index'], resolve),
      name: 'media-audit',
      meta: { title: '媒体审核', icon: 'audit' }
    }, {
      path: 'media-template',
      component: resolve => require(['@/views/media/media-template/index'], resolve),
      name: 'media-template',
      meta: { title: '模板制作', icon: 'template' }
    }, {
      path: 'media-mkshow',
      component: resolve => require(['@/views/media/media-mkshow/index'], resolve),
      name: 'media-mkshow',
      meta: { title: '节目制作', icon: 'mediacenter' }
    }, {
      path: 'media-pubshow',
      component: resolve => require(['@/views/media/media-pubshow/index'], resolve),
      name: 'media-pubshow',
      meta: { title: '节目发布', icon: 'release' }
    }]
  },
  {
    path: '/system',
    component: Layout,
    meta: {
      title: '系统管理',
      icon: 'system'
    },
    children: [{
        path: 'actor-manage',
        component: resolve => require(['@/views/system/actor-manage/index'], resolve),
        name: 'actor-manage',
        meta: { title: '角色管理', icon: 'roles' }
      },
      {
        path: 'user-manage',
        component: resolve => require(['@/views/system/user-manage/index'], resolve),
        name: 'user-manage',
        meta: { title: '用户管理', icon: 'usermanage' }
      },
      {
        path: 'operation-log',
        component: resolve => require(['@/views/system/operation-log/index'], resolve),
        name: 'operation-log',
        meta: { title: '操作日志', icon: 'operating' }
      },
      {
        path: 'count-summary',
        component: resolve => require(['@/views/system/count-summary/index'], resolve),
        name: 'count-summary',
        meta: { title: '统计汇总', icon: 'chart' }
      },
      {
        path: 'system-maintain',
        component: resolve => require(['@/views/system/system-maintain/index'], resolve),
        name: 'system-maintain',
        meta: { title: '系统维护', icon: 'maintain' }
      },
    ]
  },
  {
    path: '/helpcenter',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: resolve => require(['@/views/system/help-center/index'], resolve),
        name: 'help-center',
        meta: { title: '帮助中心', icon: 'warning', affix: false }
      }
    ]
  },
  {
    path: '/personal',
    component: Layout,
    meta: {
      title: '个人管理',
      icon: 'system'
    },
    children: [
      {
        path: 'personal-center',
        component: resolve => require(['@/views/personal/index'], resolve),
        name: 'personal-center',
        meta: { title: '个人中心', icon: 'warning', affix: false }
      }
    ]
  },
  {
    path: '/xml',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: resolve => require(['@/views/device/components/xml'], resolve),
        name: 'play-detail',
        meta: { title: '播放监控详情', icon: 'warning', affix: false }
      }
    ]
  }
]

const createRouter = () => new Router({
  mode: 'history',
  scrollBehavior() {
    return { x: 0, y: 0 }
  },
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
